<?php
/**
 * TinyMVC - TinyMVC.class.php file
 *
 * @author Adrian Wieczorek <adi(at)tinymvc(dot)org>
 * @package TinyMVC
 * @version $Id: TinyMVC.class.php 7 2007-09-12 22:09:47Z adi3ek $
 *
 */

/**
 * TinyMVC class
 * @package TinyMVC
 */
final class TinyMVC {

	static private $instance = null;
	private $startTime;

	private function __construct() {
		$this->startTime = microtime(true);
	}

	private function __clone() {
	}

	/**
	 * get class instance
	 * @return TinyMVC
	 */
	static public function getInstance() {
 	if(self::$instance == null) {
			try {
				if(!defined('TINYMVC_PATH')) {
					throw new TinyMVCException('TINYMVC_PATH has not been definded');
				}
				else	{
					if(file_exists(TINYMVC_PATH)) {
						self::$instance = new TinyMVC();
					}
					else {
						throw new TinyMVCException('Incorrect TINYMVC_PATH: ' . TINYMVC_PATH);
					}
				}

			}
			catch(Exception $exception) {
				$exception->handleException();
			}
		}
		return self::$instance;
	}

	/**
	 * add new path to PHP include_path
	 * @param string $path path to add
	 */
	public function addIncludePath($path) {
	 try {
			if(file_exists($path)) {
			 $includePath = ini_get('include_path');
			 $includePath.= PATH_SEPARATOR . $path;

			 ini_set('include_path', $includePath);
			}
			else {
				throw new TinyMVCException("Invalid include path: $path");
			}
	 }
	 catch(Exception $exception) {
			$exception->handleException();
	 }
	}
	
	/**
	 * get execution time since TinyMVC object was created until now
	 * @return float execution time
	 */
	public function getExecTime() {
		return microtime(true) - $this->startTime;
	}
}
